gtkgesture: Apply gesture group state after setting up sequence
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 17 May 2021 21:34:44 +0000 (23:34 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 17 May 2021 22:16:12 +0000 (00:16 +0200)
When a new sequence is added to a GtkGesture, its state is looked
in other gestures in the same group, and made to match in this
gesture. This however happened a bit too early, before the
gesture touchpoint was fully set up. As this may result in signal
emission and whatnot, it's a good idea to make it happen with a
fully set up touchpoint.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/3946
gtk/gtkgesture.c

index c345eb98e5848433946510fb664cf82777a68d0f..ea1b5b8cf8c340dfec21066b994345597d9080f6 100644 (file)
@@ -477,8 +477,6 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
                                           NULL, (gpointer *) &data);
   if (!existed)
     {
-      GtkEventSequenceState group_state;
-
       if (!add)
         return FALSE;
 
@@ -490,9 +488,6 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
 
       data = g_new0 (PointData, 1);
       g_hash_table_insert (priv->points, sequence, data);
-
-      group_state = gtk_gesture_get_group_state (gesture, sequence);
-      gtk_gesture_set_sequence_state (gesture, sequence, group_state);
     }
 
   if (data->event)
@@ -504,13 +499,24 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
   data->widget_x = x + data->accum_dx;
   data->widget_y = y + data->accum_dy;
 
-  /* Deny the sequence right away if the expected
-   * number of points is exceeded, so this sequence
-   * can be tracked with gtk_gesture_handles_sequence().
-   */
-  if (!existed && _gtk_gesture_get_n_physical_points (gesture, FALSE) > priv->n_points)
-    gtk_gesture_set_sequence_state (gesture, sequence,
-                                    GTK_EVENT_SEQUENCE_DENIED);
+  if (!existed)
+    {
+      GtkEventSequenceState state;
+
+      /* Deny the sequence right away if the expected
+       * number of points is exceeded, so this sequence
+       * can be tracked with gtk_gesture_handles_sequence().
+       *
+       * Otherwise, make the sequence inherit the same state
+       * from other gestures in the same group.
+       */
+      if (_gtk_gesture_get_n_physical_points (gesture, FALSE) > priv->n_points)
+        state = GTK_EVENT_SEQUENCE_DENIED;
+      else
+        state = gtk_gesture_get_group_state (gesture, sequence);
+
+      gtk_gesture_set_sequence_state (gesture, sequence, state);
+    }
 
   return TRUE;
 }